import QtQuick 1.0

Rectangle {
    id: balloonFullScreen
    width: parent.width
    height: parent.height
    color: "#aa000000"
    property alias text: caption.text
    property string tag
    signal dismissed(string tag)
    signal yes(string tag)
    signal no(string tag)
    visible: false

    states: [
        State {
            name: "dismiss"
            PropertyChanges {
                target: ok
                visible: true
            }
            PropertyChanges {
                target: yes
                visible: false
            }
            PropertyChanges {
                target: no
                visible: false
            }
            PropertyChanges {
                target: mouseArea
                enabled: true
            }
        },

        State {
            name: "confirm"
            PropertyChanges {
                target: ok
                visible: false
            }
            PropertyChanges {
                target: yes
                visible: true
            }
            PropertyChanges {
                target: no
                visible: true
            }
            PropertyChanges {
                target: mouseArea
                enabled: false
            }
        }
    ]

    function show(t, str) {
        tag = t
        state = "dismiss"
        text = str;
        visible = true
        animShow.start();
    }

    function hide() {
        animHide.start();
    }

    function confirm(t, str) {
        tag = t
        state = "confirm"
        text = str;
        visible = true
        animShow.start();
    }

    Image {
        anchors.horizontalCenter: parent.horizontalCenter
        id: balloonImg
        source: "assets/balloon.png"
        Text {
            id: caption
            font.family: throwHands.name
            font.pointSize: 8
            y: balloonImg.height / 8
            width: balloonImg.width * 3 / 4
            wrapMode: "WordWrap"
            anchors.horizontalCenter: parent.horizontalCenter
        }

        Text {
            id: ok
            font.family: throwHands.name
            font.pointSize: 8
            y: balloonImg.height / 2
            text: "OK"
            anchors.horizontalCenter: parent.horizontalCenter
        }

        Text {
            id: yes
            font.family: throwHands.name
            font.pointSize: 8
            y: balloonImg.height * 3 / 8
            text: "Yes"
            anchors.horizontalCenter: parent.horizontalCenter

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    //animHide.start()
                    balloonFullScreen.yes(tag)
                }
            }
        }

        Text {
            id: no
            font.family: throwHands.name
            font.pointSize: 8
            y: balloonImg.height / 2
            text: "No"
            anchors.horizontalCenter: parent.horizontalCenter

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    //animHide.start()
                    balloonFullScreen.no(tag)
                }
            }
        }
    }

    SequentialAnimation {
        id: animShow
        running: false
        PropertyAnimation {
            duration: 1500
            target: balloonImg
            property: "y"
            from: parent.height
            to: (parent.height - balloonImg.height) / 2
        }
    }

    SequentialAnimation {
        id: animHide
        running: false
        PropertyAnimation {
            duration: 1500
            target: balloonImg
            property: "y"
            to: -balloonImg.height
        }
        ScriptAction {
            script: balloonFullScreen.visible = false
        }
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            animHide.start()
            balloonFullScreen.dismissed(tag);
        }
    }
}
